home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / SoftBevelBorder.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  155 lines

  1. /*
  2.  * @(#)SoftBevelBorder.java    1.5 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20. package com.sun.java.swing.border;
  21.  
  22. import java.awt.Graphics;
  23. import java.awt.Insets;
  24. import java.awt.Rectangle;
  25. import java.awt.Color;
  26. import java.awt.Component;
  27.  
  28.  
  29. /**
  30.  * A class which implements a raised or lowered bevel with
  31.  * softened corners.
  32.  * <p>
  33.  * Warning: serialized objects of this class will not be compatible with
  34.  * future swing releases.  The current serialization support is appropriate
  35.  * for short term storage or RMI between Swing1.0 applications.  It will
  36.  * not be possible to load serialized Swing1.0 objects with future releases
  37.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  38.  * baseline for the serialized form of Swing objects.
  39.  *
  40.  * @version 1.5 02/02/98
  41.  * @author Amy Fowler
  42.  * @author Chester Rose
  43.  */
  44. public class SoftBevelBorder extends BevelBorder
  45. {
  46.  
  47.     /**
  48.      * Creates a bevel border with the specified type and whose
  49.      * colors will be derived from the background color of the
  50.      * component passed into the paintBorder method.
  51.      * @param bevelType the type of bevel for the border
  52.      */
  53.     public SoftBevelBorder(int bevelType) {
  54.         super(bevelType);
  55.     }
  56.  
  57.     /**
  58.      * Creates a bevel border with the specified type, highlight and
  59.      * shadow colors.
  60.      * @param bevelType the type of bevel for the border
  61.      * @param highlight the color to use for the bevel highlight
  62.      * @param shadow the color to use for the bevel shadow
  63.      */
  64.     public SoftBevelBorder(int bevelType, Color highlight, Color shadow) {
  65.         super(bevelType, highlight, shadow);
  66.     }
  67.  
  68.     /**
  69.      * Creates a bevel border with the specified type, highlight
  70.      * shadow colors.
  71.      * @param bevelType the type of bevel for the border
  72.      * @param highlightOuter the color to use for the bevel outer highlight
  73.      * @param highlightInner the color to use for the bevel inner highlight
  74.      * @param shadowOuter the color to use for the bevel outer shadow
  75.      * @param shadowInner the color to use for the bevel inner shadow
  76.      */
  77.     public SoftBevelBorder(int bevelType, Color highlightOuter, Color highlightInner,
  78.                         Color shadowOuter, Color shadowInner) {
  79.         super(bevelType, highlightOuter, highlightInner, shadowOuter, shadowInner);
  80.     }
  81.  
  82.     /**
  83.      * Paints the border for the specified component with the specified
  84.      * position and size.
  85.      * @param c the component for which this border is being painted
  86.      * @param g the paint graphics
  87.      * @param x the x position of the painted border
  88.      * @param y the y position of the painted border
  89.      * @param width the width of the painted border
  90.      * @param height the height of the painted border
  91.      */
  92.     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  93.         Color oldColor = g.getColor();
  94.         g.translate(x, y);
  95.  
  96.         if (bevelType == RAISED) {
  97.         g.setColor(getHighlightOuterColor(c));
  98.         g.drawLine(0, 0, width-2, 0);
  99.         g.drawLine(0, 0, 0, height-2);
  100.         g.drawLine(1, 1, 1, 1);
  101.         
  102.         g.setColor(getHighlightInnerColor(c));
  103.         g.drawLine(2, 1, width-2, 1);
  104.         g.drawLine(1, 2, 1, height-2);
  105.         g.drawLine(2, 2, 2, 2);
  106.         g.drawLine(0, height-1, 0, height-2);
  107.         g.drawLine(width-1, 0, width-1, 0);
  108.         
  109.         g.setColor(getShadowOuterColor(c));
  110.         g.drawLine(2, height-1, width-1, height-1);
  111.         g.drawLine(width-1, 2, width-1, height-1);
  112.         
  113.         g.setColor(getShadowInnerColor(c));
  114.         g.drawLine(width-2, height-2, width-2, height-2);        
  115.  
  116.  
  117.         } else if (bevelType == LOWERED) {
  118.         g.setColor(getShadowOuterColor(c));
  119.         g.drawLine(0, 0, width-2, 0);
  120.         g.drawLine(0, 0, 0, height-2);
  121.         g.drawLine(1, 1, 1, 1);
  122.         
  123.         g.setColor(getShadowInnerColor(c));
  124.         g.drawLine(2, 1, width-2, 1);
  125.         g.drawLine(1, 2, 1, height-2);
  126.         g.drawLine(2, 2, 2, 2);
  127.         g.drawLine(0, height-1, 0, height-2);
  128.         g.drawLine(width-1, 0, width-1, 0);
  129.         
  130.         g.setColor(getHighlightOuterColor(c));
  131.         g.drawLine(2, height-1, width-1, height-1);
  132.         g.drawLine(width-1, 2, width-1, height-1);
  133.         
  134.         g.setColor(getHighlightInnerColor(c));
  135.         g.drawLine(width-2, height-2, width-2, height-2);        
  136.         }
  137.         g.translate(-x, -y);
  138.         g.setColor(oldColor);
  139.     }
  140.  
  141.     /**
  142.      * Returns the insets of the border.
  143.      * @param c the component for which this border insets value applies
  144.      */
  145.     public Insets getBorderInsets(Component c)       {
  146.     return new Insets(3, 3, 3, 3);
  147.     }
  148.  
  149.     /**
  150.      * Returns whether or not the border is opaque.
  151.      */
  152.     public boolean isBorderOpaque() { return false; }
  153.  
  154. }
  155.